Skip to content

feat: Python SDK (Surface 2) + run-control API + adapters (step 8) - #6

Merged
prashar32 merged 1 commit into
mainfrom
feat/step-8-python-sdk
May 30, 2026
Merged

feat: Python SDK (Surface 2) + run-control API + adapters (step 8)#6
prashar32 merged 1 commit into
mainfrom
feat/step-8-python-sdk

Conversation

@prashar32

Copy link
Copy Markdown
Owner

What & why

Implements Surface 2 — the Python SDK (§8 step 8): deep, in-process control over a governed run. The SDK is a thin, stdlib-only client; the Go core makes every deterministic decision (budgets, halts, approval policy).

Go — run-control endpoints (additive to api/v1)

  • POST /v1/runs (create with budget), POST /v1/runs/{id}/steps (loop/time enforcement → 402 on halt), POST /v1/runs/{id}/checkpoints, POST /v1/runs/{id}/cancel, POST /v1/runs/{id}/approvals (non-blocking request), GET /v1/approvals/{id} (poll).
  • approval.Gate.Create for the SDK poll model. Tests cover every endpoint (loop-budget 402, checkpoint round-trip, approval request→poll→resolve, auto-approve).

Python — pip install riskkernel (zero runtime deps)

  • Runtime / governed_run / Budget; Run.step/checkpoint/cancel/proxy_config; ApprovalGate + @governed_tool; current_run contextvar.
  • Model-call metering stays in the proxy — route the SDK's LLM calls through run.proxy_config(), so the SDK never re-implements governance.
  • Lazy-imported adapters (no hard deps): LangChain CallbackHandler, Claude Agent SDK PreToolUse hook, OpenAI Agents SDK RunHooks.
  • pyproject (hatchling), README, unittest suite against a stdlib stub daemon.

Verification

  • go test -race ./... green; vet + gofmt clean.
  • Python SDK suite green (8 tests); CI job on Python 3.9 / 3.12.
  • End-to-end against the real daemon: governed run → loop-budget BudgetExceeded → checkpoint round-trip → approval request→resolve→approved → read-only auto-approve.

Deep control over a governed run from Python. The SDK is a thin, stdlib-only
client; the Go core makes every deterministic decision.

Go (run-control endpoints the SDK drives):
- POST /v1/runs (create with budget), POST /v1/runs/{id}/steps (loop/time
  enforcement -> 402 on halt), POST /v1/runs/{id}/checkpoints,
  POST /v1/runs/{id}/cancel, POST /v1/runs/{id}/approvals (request, non-blocking),
  GET /v1/approvals/{id} (poll). approval.Gate.Create added for the poll model.
- api/v1 extended additively; tests for every endpoint incl. loop-budget 402,
  checkpoint round-trip, approval request->poll->resolve.

Python (sdks/python, package `riskkernel`, zero runtime deps):
- client.RiskKernel (urllib); 402 -> BudgetExceeded.
- Runtime / governed_run / Budget / Run (step, checkpoint, cancel, proxy_config);
  ApprovalGate + @governed_tool; current_run contextvar; env-configured default.
- Adapters (lazy-imported, no hard deps): LangChain CallbackHandler,
  Claude Agent SDK PreToolUse hook, OpenAI Agents SDK RunHooks.
- pyproject (hatchling, Apache-2.0), README, unittest suite against a stdlib
  stub daemon. Verified end-to-end against the real daemon.
- CI: Python SDK workflow on 3.9 / 3.12.

Model-call metering stays in the proxy: route the SDK's LLM calls through
run.proxy_config(), so the SDK never re-implements governance.
@prashar32
prashar32 merged commit 93afabf into main May 30, 2026
5 checks passed
@prashar32
prashar32 deleted the feat/step-8-python-sdk branch May 30, 2026 17:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant